package com.car.servlet;

import com.car.entyti.User;
import com.car.service.CarpoolService;
import com.car.entyti.Carpool;
import com.car.service.UserService;
import com.google.gson.Gson;
import jdk.nashorn.internal.parser.Token;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/json")
public class jsonServlet extends HttpServlet {
    CarpoolService carpoolService = new CarpoolService();
    UserService userService =new UserService();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        Carpool carpool =new Carpool();
        carpool.setId(req.getParameter("id"));
        List<Carpool> carpoolList = carpoolService.carpoolList();


        if (carpoolList != null){
            resp.setContentType("application/json;charset=utf-8");
            resp.getWriter().print(new Gson().toJson(carpoolList));
        }
    }


}
